package com.util;

import lombok.Data;

@Data
public class AjaxResult {

    /**
     * 返回标识
     */
    private int code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 数据主体标识
     */
    private Object data;

    public AjaxResult(){}

    public static AjaxResult getOk(String msg, Object data){
        AjaxResult r = new AjaxResult();
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static AjaxResult getOk(){
        AjaxResult r = new AjaxResult();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData("");
        return r;
    }

    public static AjaxResult getOk(Object data){
        AjaxResult r = new AjaxResult();
        r.setCode(200);
        r.setMsg("操作成功");
        r.setData(data);
        return r;
    }

    public static AjaxResult getOk(String msg){
        AjaxResult r = new AjaxResult();
        r.setCode(200);
        r.setMsg(msg);
        return r;
    }

    public static AjaxResult getFail(int code,String msg){
        AjaxResult r = new AjaxResult();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static AjaxResult getFail(String msg, Object data){
        AjaxResult r = new AjaxResult();
        r.setCode(500);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static AjaxResult getFail(){
        AjaxResult r = new AjaxResult();
        r.setCode(500);
        r.setMsg("操作失败");
        return r;
    }

    public static AjaxResult getFail(Object data){
        AjaxResult r = new AjaxResult();
        r.setCode(500);
        r.setMsg("操作失败");
        r.setData(data);
        return r;
    }

    public static AjaxResult getFail(String msg){
        AjaxResult r = new AjaxResult();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }

}
